package org.elfen.sys.entity;

import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.Pattern;

import org.elfen.common.base.BaseEntity;
import org.elfen.common.util.DataUtil;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;

/**
DROP TABLE IF EXISTS sys_user;
CREATE TABLE sys_user (
  id bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键id',
  createTime datetime DEFAULT NULL COMMENT '创建时间',
  createBy varchar(100) DEFAULT '' COMMENT '创建人',
  isDelete  int(2) DEFAULT '0' COMMENT '是否已删除：0-未删除，1-删除',
  
  userName varchar(256) NOT NULL COMMENT '用户账号：唯一',
  userPassword varchar(256) NOT NULL,
  userNick varchar(256) NOT NULL COMMENT '用户昵称：唯一',
  userQQ varchar(256) NOT NULL COMMENT '用户QQ：唯一',
  weixin varchar(256) DEFAULT '',
  phone varchar(256) DEFAULT '',
  taobao varchar(256) DEFAULT NULL COMMENT '用户淘宝账号：唯一、选填',
  userType int(11) NOT NULL DEFAULT '1' COMMENT '用户类型：普通、会员等等，默认：普通',
  userGrade int(11) NOT NULL DEFAULT '1' COMMENT '用户等级,默认：1',
  isEnable int(11) NOT NULL COMMENT '是否启用',
  ext1 varchar(256) DEFAULT '',
  ext2 varchar(256) DEFAULT '',
  ext3 varchar(256) DEFAULT '',
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='系统用户表';

 * @author eztouch
 *
 */
@SuppressWarnings("serial")
@TableName("sys_user")
public class SysUser extends BaseEntity{
	@NotEmpty(message="账号不能为空！")
	@Length(max=16,message="账号不能超过16个字符！")
	@Pattern(regexp="^[a-zA-Z0-9]+$",message="账号只能包含数字或者英文！")
	private String userName;
	@NotEmpty(message="密码不能为空！")
//	@Length(min=4,max=8,message="密码必须是4-8位！")
	@Pattern(regexp="^[a-zA-Z0-9]+$",message="密码只能包含数字或者英文！")
	private String userPassword;
	@NotEmpty(message="昵称不能为空！")
	private String userNick;
	@NotEmpty(message="QQ不能为空！")
	@Pattern(regexp="^[1-9][0-9]{4,}$",message="QQ号码不合法！")
	private String userQQ;
	@ApiModelProperty(hidden=true)
	private String weixin;
//	@Pattern(regexp="/^(0|86|17951)?(13[0-9]|15[012356789]|18[0-9]|14[57])[0-9]{8}$/",message="手机号码不合法！")
	@ApiModelProperty(hidden=true)
	private String phone;
	@ApiModelProperty(hidden=true)
	private String taobao;
	@ApiModelProperty(example="1")
	private Integer userType;
	@ApiModelProperty(example="1")
	private Integer userGrade;
	@ApiModelProperty(allowableValues="[0,1]")
	private Integer isEnable;//0-启用，1-禁用
	@ApiModelProperty(hidden=true)
	private String ext1;
	@ApiModelProperty(hidden=true)
	private String ext2;
	@ApiModelProperty(hidden=true)
	private String ext3;
	
	@ApiModelProperty(hidden=true)
	@TableField(exist=false)
	private String oldPassword;
	
	
	@Override
	public Wrapper<SysUser> bindingQueryWrapper() {
		Wrapper<SysUser> wrapper = new EntityWrapper<SysUser>();
		if(DataUtil.isNotEmpty(this.userName)){
			wrapper.eq("userName", this.userName);
		}
		if(DataUtil.isNotEmpty(this.userNick)){
			wrapper.eq("userNick", this.userNick);
		}
		if(DataUtil.isNotEmpty(this.isDelete)){
			wrapper.eq("isDelete", this.isDelete);
		}
		if(DataUtil.isNotEmpty(this.userQQ)){
			wrapper.eq("userQQ", this.userQQ);
		}
		if(DataUtil.isNotEmpty(this.phone)){
			wrapper.eq("phone", this.phone);
		}
		if(DataUtil.isNotEmpty(this.taobao)){
			wrapper.eq("taobao", this.taobao);
		}
		if(DataUtil.isNotEmpty(this.userType)){
			wrapper.eq("userType", this.userType);
		}
		
		return wrapper;
	}


	public String getUserName() {
		return userName;
	}


	public void setUserName(String userName) {
		this.userName = userName;
	}


	public String getUserPassword() {
		return userPassword;
	}


	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}


	public String getUserNick() {
		return userNick;
	}


	public void setUserNick(String userNick) {
		this.userNick = userNick;
	}


	public String getUserQQ() {
		return userQQ;
	}


	public void setUserQQ(String userQQ) {
		this.userQQ = userQQ;
	}


	public String getWeixin() {
		return weixin;
	}


	public void setWeixin(String weixin) {
		this.weixin = weixin;
	}


	public String getPhone() {
		return phone;
	}


	public void setPhone(String phone) {
		this.phone = phone;
	}


	public String getTaobao() {
		return taobao;
	}


	public void setTaobao(String taobao) {
		this.taobao = taobao;
	}


	public Integer getUserType() {
		return userType;
	}


	public void setUserType(Integer userType) {
		this.userType = userType;
	}


	public Integer getUserGrade() {
		return userGrade;
	}


	public void setUserGrade(Integer userGrade) {
		this.userGrade = userGrade;
	}


	public Integer getIsEnable() {
		return isEnable;
	}


	public void setIsEnable(Integer isEnable) {
		this.isEnable = isEnable;
	}

	public String getExt1() {
		return ext1;
	}

	public void setExt1(String ext1) {
		this.ext1 = ext1;
	}

	public String getExt2() {
		return ext2;
	}

	public void setExt2(String ext2) {
		this.ext2 = ext2;
	}


	public String getExt3() {
		return ext3;
	}


	public void setExt3(String ext3) {
		this.ext3 = ext3;
	}


	public String getOldPassword() {
		return oldPassword;
	}


	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((ext1 == null) ? 0 : ext1.hashCode());
		result = prime * result + ((ext2 == null) ? 0 : ext2.hashCode());
		result = prime * result + ((ext3 == null) ? 0 : ext3.hashCode());
		result = prime * result
				+ ((isEnable == null) ? 0 : isEnable.hashCode());
		result = prime * result
				+ ((oldPassword == null) ? 0 : oldPassword.hashCode());
		result = prime * result + ((phone == null) ? 0 : phone.hashCode());
		result = prime * result + ((taobao == null) ? 0 : taobao.hashCode());
		result = prime * result
				+ ((userGrade == null) ? 0 : userGrade.hashCode());
		result = prime * result
				+ ((userName == null) ? 0 : userName.hashCode());
		result = prime * result
				+ ((userNick == null) ? 0 : userNick.hashCode());
		result = prime * result
				+ ((userPassword == null) ? 0 : userPassword.hashCode());
		result = prime * result + ((userQQ == null) ? 0 : userQQ.hashCode());
		result = prime * result
				+ ((userType == null) ? 0 : userType.hashCode());
		result = prime * result + ((weixin == null) ? 0 : weixin.hashCode());
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		SysUser other = (SysUser) obj;
		if (ext1 == null) {
			if (other.ext1 != null)
				return false;
		} else if (!ext1.equals(other.ext1))
			return false;
		if (ext2 == null) {
			if (other.ext2 != null)
				return false;
		} else if (!ext2.equals(other.ext2))
			return false;
		if (ext3 == null) {
			if (other.ext3 != null)
				return false;
		} else if (!ext3.equals(other.ext3))
			return false;
		if (isEnable == null) {
			if (other.isEnable != null)
				return false;
		} else if (!isEnable.equals(other.isEnable))
			return false;
		if (oldPassword == null) {
			if (other.oldPassword != null)
				return false;
		} else if (!oldPassword.equals(other.oldPassword))
			return false;
		if (phone == null) {
			if (other.phone != null)
				return false;
		} else if (!phone.equals(other.phone))
			return false;
		if (taobao == null) {
			if (other.taobao != null)
				return false;
		} else if (!taobao.equals(other.taobao))
			return false;
		if (userGrade == null) {
			if (other.userGrade != null)
				return false;
		} else if (!userGrade.equals(other.userGrade))
			return false;
		if (userName == null) {
			if (other.userName != null)
				return false;
		} else if (!userName.equals(other.userName))
			return false;
		if (userNick == null) {
			if (other.userNick != null)
				return false;
		} else if (!userNick.equals(other.userNick))
			return false;
		if (userPassword == null) {
			if (other.userPassword != null)
				return false;
		} else if (!userPassword.equals(other.userPassword))
			return false;
		if (userQQ == null) {
			if (other.userQQ != null)
				return false;
		} else if (!userQQ.equals(other.userQQ))
			return false;
		if (userType == null) {
			if (other.userType != null)
				return false;
		} else if (!userType.equals(other.userType))
			return false;
		if (weixin == null) {
			if (other.weixin != null)
				return false;
		} else if (!weixin.equals(other.weixin))
			return false;
		return true;
	}

	
}
